<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.autotab.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.form.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.validate.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/cmxforms.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.metadata.js"></script>
<script type="text/javascript" src="catalog/view/javascript/fckeditor/fckeditor.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.alphanumeric.pack.js"></script>
<!--begin add code by D-Ngan April 1-->
<script type="text/javascript">
$.metadata.setType("attr", "validate");
$(document).ready(function() {
	//$('#price').autotab({ target: 'price', format: 'pricea', previous: 'price' });
	$("#form").validate({
		rules:{
				catalog_child: "required",
				catalog_parent: "required",
				zone_id: "required",
				price:{
					required: false,
      				digits: false
				},
				shop_name:{
					required: true,
					minlength:3,
					maxlength:50
				},
				name:{
					required: true,
					minlength:3,
					maxlength:100
				},
				address:{
					required:true,
					maxlength:255
				},
				image:{
					accept:"gif|jpg|jpeg|pjpeg|png|x-png"
				},
				detail_info:{
					required:false,
					minlength:0
				}
			},
		messages: {
			catalog_child: "Chọn danh mục sản phẩm",
			zone_id: "Chọn khu vực bán",
			catalog_parent: "Chọn danh mục sản phẩm",
			price:{
				required:"Nhập giá sản phẩm",
				digits:"Giá sản phẩm phải là một số"
			},
			image:{
				accept:"Chỉ nhập định dạng .gif|jpg|jpeg|pjpeg|png|x-png"
			},
			address:{
				required:"Nhập địa chỉ shop",
				maxlength:"Tối đa 255 ký tự"
			},
			shop_name: {
				required:"Nhập tên shop",
				minlength:"Tối thiểu 3 ký tự",
				maxlength:"Tối đa 30 ký tự"
			},
			name: {
				required:"Nhập tên sản phẩm",
				minlength:"Tối thiểu 3 ký tự",
				maxlength:"Tối đa 100 ký tự"
			},
			detail_info:{
				required:"Nhập thông tin mô tả thông tin sản phẩm",
				minlength:"Thông tin sản phẩm tối thiểu 12 ký tự"
			}
		}
	});
});
</script>

<style type="text/css">
	.cmxform .upload div  {
		width: 760px;
		margin-left: 30px;
		padding-top: 5px;
	}
	.cmxform .upload .rows{
		clear:both;
	}
	.cmxform .upload .rows .title {
		height: 15px;
		width: 710px;		
		background: #f2faff;
		border:1px solid #9cc5da;
		padding:2px 10px;
		-moz-border-radius: 1em 1em 1em 1em;
		-webkit-border-radius: 1em 1em 1em 1em;
		border-radius: 1em 1em 1em 1em;
	}

	.cmxform .upload .rows .title label {
		color: #276fa1;
		font-size:14pxm;
		font-weight:bold;
	}

	.items {
		float:left;
		height: 20px;
	}
	.input_textbox{
	}

	#image{
		margin-left:30px;
		height: 23px;
		width: 500px;
		color: black;
	}
	.items .error{
		float:left;
		margin-left:10px;
	}


    #payment_sub {
    	display: none;
    }
    .block { display: block; }
	.selection_items{
		font-size:16px;
		height:30px;
		
	}
	.selection_items:hover{ 	
		background-color:#0FF;
	}
	.selection_items:active{
		
		border:1px solid;
		border-color:#00F;
		background-color:#0FF;
	}

</style>
<!--
<style type="text/css">
#form { width: 00px; }
#form label { width: 250px; }
#form label.error, #form input.submit { margin-left: 253px; }
#form { width: 670px; }
#form label.error {
	margin-left: 10px;
	width: auto;
	display: inline;
}

#newsletter_topics label.error {
	display: none;
	margin-left: 103px;
}
</style>-->

<form method="post" name="form" enctype="multipart/form-data" class="cmxform" id="form" action="<?php echo $action; ?>">
    <div style="width: 75%; height:100%;  margin-left: 70px;">
        <div class="upload" style="float:left; width: 800px; margin-left: 10px; padding-top: 10px; background-color: #F6F9FF">
            <div style="border-bottom: 1px solid #EA6F1F;margin-bottom: 15px; padding-bottom: 0px; position: relative;">
                <div style="padding-bottom: 10px; text-transform:uppercase; color: #d8630e;font-size: 16px;font-weight: bold;text-shadow:1px 1px 2em #ff7510;">
                    <b>Đăng sản phẩm</b>
                </div>
            </div> <!--Tieu dề-->
            <div class="rows">
                	<div style="float:left; color:#007F00; margin-left:10px; font-size:14px;" >						
                            <input type="radio" style="width: 15px;" onclick="doShow();" checked="checked" id="sale_flg1" value="1" name="sale_flg"  /> 
                            Đăng bán&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="radio" style="width: 15px" id="sale_flg2" onclick="doHide();" value="2" name="sale_flg"  /> Đăng mua
					</div >
            </div><!--Bán hay mua-->
            <?php if(isset($shop_name) == false) { ?>
             <input type="hidden" id="shop_name" name="shop_name" value="<?php echo $this->customer->getUsername().'_shop';?>"/>
             <input  type="hidden" id="address" name="address" value="<?php echo $this->customer->getUsername().'_address';?>"/>
            <!--Thông tin gian hàng--><?php
			
            }?>
            <div class="rows" >
                <div style="color:#007F00;font-weight:bold;font-size:14px;">
                    <label for="product">Danh mục sản phẩm</label>
                </div>
                <div style="margin-left:90px;float:left; width:260px;">
                  <select name="catalog_parent" id="catalog_parent" onchange="loadChildCatalog(this.value);doSumary(0);" style="width:250px;" size="10" >
                      <?php foreach ($parent_catalog as $catagory) { ?>
                            <option class="selection_items" value="<?php echo $catagory['catalog_id']; ?>"><?php echo $catagory['name']; ?></option>
                      <?php } ?>
                  </select>
                </div>
                <div id="catalog_child1" style="float:left; width:260px;" >
                    <select disabled="disabled" name="catalog_child" id="catalog_child" style="width:250px;" onchange="doSumary(this.value);">
                        <option class="selection_items" value="">Chọn danh mục cấp 2</option>
                    </select>
                </div>
            </div><!--Catagory-->
            <div class="rows" id="description" style="height:450px;">
                <div class="title">
                    <label for="product">Mô tả sản phẩm</label>
                </div>
                <div class="entry">
                	<div style="clear:both;">
                    	<span class="items">Tiêu đề tin bán (*): </span> 
                        <input class="items" style="width:400px; margin-left:10px;"  id="name" name="name" size="60" />
                    </div>
                    <div style="clear:both;">
                   	 <span class="items"> Phạm vi đăng: </span>
                      <select  class="items" style="margin-left:35px;width:100px;" name="zone_id" id="zone_id">
                        <?php foreach ($areas as $area) { ?>
                              <option value="<?php echo $area['zone_id']; ?>"><?php echo $area['name']; ?></option>
                        <?php } ?>
                      </select>
                    </div>
                    
                    <div class="title2" style="clear: both;">
                        <label for="product">Hình ảnh</label>
                        <input style=" margin-left:60px;"  size="60px;" type="file" id="image" name="image"  />
                    </div>
                    
             
                    <div class="title2">
                        <label for="product">Giá sản phẩm</label>
                         <input  id="price" onkeyup="return auto_currency('price');" name="price" style="width:340px;margin-left:35px;text-align:right" />
                        	<select name="price_type" id="price_type" style="width: 60px; height: 20px; margin-left: 5px;" >
                            	<option value="VN" selected="selected">VND</option>
                            	<option value="USA">USA</option>
                        	</select>
                    </div>
                  <div class="title2">
                        <label for="user">Chi tiết sản phẩm</label>
                  </div>
                  <div>
                  		<textarea id="detail_info" name="detail_info" rows="15" cols="120" style="width: 600px; margin-left: 50px; color: black"></textarea>
                  </div>
                </div>
            </div><!--End Mô tả sản phẩm-->
            
            <div id="checkout" class="rows" style="height: 170px;">
                <div class="title">
                    <label for="product">Thanh toán</label>
                </div>
                <div class="items" id="pay" style="clear: both; ">
                        <div class="title3">
                            <input type="radio" style="width: 15px;" id="payment1" checked="checked" value="1" name="payment"/>
                            <label>Xem hàng và trả tiền trực tiếp</label>
                        </div>
                        <div class="title2" style="clear: both;">
                            <input type="radio" style="width: 15px" id="payment2" value="2" name="payment"  /> Chuyển tiền trước nhận hàng sau
                        </div>
                        <div class="title2" style="clear: both;">
                            <input type="radio" style="width: 15px" id="" value="3" name="payment"  /> Đặt hàng trước, 3 ngày sau nhận hàng
                        </div>
                        <div class="title2" style="clear: both;">
                            <input type="radio" style="width: 15px" id="" value="4" name="payment"  /> Xem hàng và trả tiền trực tiếp hoặc chuyển tiền trước nhận hàng sau
                        </div>
                </div>
            </div><!--Mo tả chi tiết sản phẩm-->
            <div class="rows" id="button">
                <div class="items2">
                    <input class="button" style="height:30px;margin-left:300px;padding:0 30px;font-weight:bold;" type="submit" value="Đăng Tin"/>
                </div>
            </div><!--Nut-->
        </div>
    </div>
</form><!--End form post-->

<script type="text/javascript" src="catalog/view/javascript/fckeditor/fckeditor.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.form.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.php.js"></script>
<script type="text/javascript" src="catalog/view/javascript/fckeditor/fckeditor.js"></script>


<script type="text/javascript">
	var sBasePath = document.location.href.replace(/index\.php.*/, 'catalog/view/javascript/fckeditor/');
	var oFCKeditor          = new FCKeditor('detail_info');
		oFCKeditor.BasePath = sBasePath;
		oFCKeditor.Value	   = $("#detail_info").val();
		$("#detail_info").val = "";
		oFCKeditor.Value	= "";
		oFCKeditor.Width    = '620';
		oFCKeditor.Height   = '250';
		oFCKeditor.ReplaceTextarea();
</script>

<script language="JavaScript" type="text/javascript">
	doSumary(0);
	function doSumary(varlue){
		if(varlue==0){
			$("#description").hide();
			$("#checkout").hide();
			$("#button").hide();
			
		}
		else{
			
			
			$("#description").show();
			$("#button").show();
			
			var radiovalue=1;
			for( i = 0; i < document.form.sale_flg.length; i++ )
				{
				if( document.form.sale_flg[i].checked == true )
				radiovalue = document.form.sale_flg[i].value;
				}
			if(radiovalue==1){
				$("#checkout").show();
			}
			else{
				$("#checkout").hide();
			}
		}
	}
	function auto_currency(id){
		var price_type = $('#price_type').val();
		var variable = document.getElementById(id);
		if(price_type == 'VN'){
			var new_value =  variable.value.replace(/\./g,"");
		}else{
			var new_value =  variable.value;
		}
		variable.style.textAlign = "right";
		variable.value = digit_grouping(new_value);
	}
	function digit_grouping(nStr){
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + '.' + '$2');
		}
	   return x1 + x2;
	}
	<!--End add code by D-Ngan April 1-->
	//$('#shop_name').keyup(function () {
	//    this.value = this.value.replace(/[^0-9a-zA-Z\_]/g,'');
	//});
	function loadChildCatalog(value){
		$('#catalog_child1').load('index.php?route=upload/product/childCatalogories&catalog_id=' + value,{ name : this.value });
	}
	$('#price').numeric({allow:"."});
	//$('#shop_name').alphanumeric();
</script><!--DoHide()-->